﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace BartonExtension
{
    public class FileIO
    {
        public static string ValidFileName(string filename)
        {
            string ori_fname = Path.GetFileNameWithoutExtension(filename);
            string directory = filename.Replace(Path.GetFileName(filename), "");
            string ext = Path.GetExtension(filename);
            string fname = ori_fname;
            int tag = 0;
            while(File.Exists(directory + fname + ext))
            {
                fname = ori_fname + "({0})".FormatWith(tag);
                tag++;
            }
            return fname;
        }
    }
}
